package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdWeekImportVO;
import com.yunxi.otd.pojo.OtdWeekPlanDetailVO;
import com.yunxi.otd.pojo.OtdWeekPlanSingleVO;
import com.yunxi.otd.pojo.OtdWeekPlanVO;
import com.yunxi.otd.service.OtdWeekPlanDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 周度需求计划 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-05-09
 */
@RestController
@RequestMapping("/admin/otd/week")
@Api(tags = "OTD:Week", description = "销售预测管理")
public class OtdWeekPlanController {

    private static final Logger logger = LoggerFactory.getLogger(OtdWeekPlanController.class);

    @Autowired
    OtdWeekPlanDubboService otdWeekPlanDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "主页面上传记录询")
    public ApiResult page(OtdWeekPlanVO weekPlanVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil.ok(otdWeekPlanDubboService.page(weekPlanVO, pageNum, pageSize));
    }

    @PostMapping("/import")
    @ApiOperation(value = "导入周度需求计划")
    public ApiResult importData(@RequestBody OtdWeekImportVO importDTO) {
        return otdWeekPlanDubboService.importWeekPlan(importDTO);
    }

    @GetMapping("/plan")
    @ApiOperation(value = "查看周计划")
    @ApiImplicitParam(name = "weekPlanId", value = "周计划ID", required = true, paramType = "query")
    public ApiResult weekPlan(String weekPlanId) {
        return ResponseUtil.ok(otdWeekPlanDubboService.findWeekPlanVoListByCode(weekPlanId));
    }


    @PostMapping("/add/single")
    @ApiOperation(value = "新增单车")
    public ApiResult addSingle(@RequestBody OtdWeekPlanSingleVO planVO, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.addSingle(planVO, info);
    }

    @PostMapping("/add/detail")
    @ApiOperation(value = "新增明细")
    public ApiResult addDetail(@RequestBody OtdWeekPlanDetailVO detailVO, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.addDetail(detailVO, info);
    }


    @PostMapping("/modify/plan")
    @ApiOperation(value = "修改生产计划单车")
    public ApiResult modifyPlan(@RequestBody OtdWeekPlanSingleVO planVO, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.modifyPlan(planVO, info);
    }

    @PostMapping("/remove/single")
    @ApiOperation(value = "删除周单车")
    public ApiResult removeSingle(@RequestBody String singleId, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.removeSingle(singleId, info);
    }

    @PostMapping("/modify/detail")
    @ApiOperation(value = "修改周计划明细")
    public ApiResult modifyPlanDetail(@RequestBody OtdWeekPlanDetailVO detailVO, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.modifyDetail(detailVO, info);
    }

    @PostMapping("/remove/detail")
    @ApiOperation(value = "删除周计划明细")
    public ApiResult removePlanDetail(@RequestBody String detailId, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.removeDetail(detailId, info);
    }

    @PostMapping("/release")
    @ApiOperation(value = "销售释放")
    @ApiImplicitParam(name = "weekPlanId", value = "周计划ID", required = true)
    public ApiResult releaseWeek(@RequestBody String weekPlanId, @CurrentUser LoginInfo info) {
        return otdWeekPlanDubboService.releaseWeek(weekPlanId);
    }
//
//    @PostMapping("/reject")
//    @ApiOperation(value = "生产驳回周计划")
//    public ApiResult rejectW1Plan(@RequestBody OtdWeekUploadVO otdWeekUploadVO, @CurrentUser LoginInfo info) {
//        otdWeekPlanDubboService.rejectW1Plan(otdWeekUploadVO, info);
//        return ResponseUtil.ok();
//    }
}
